<template>
	<view class="cu-item" @click="toDetail">
		<view class="cu-avatar round lg" :style="`background-image:url(${avatar});`"></view>
		<view class="content">
			<view class="text-black">
				<view class="text-cut">
					{{lecture.Name}}
				</view>
			</view>
			<view class="text-gray text-sm" :class="{'narrow-line':showBeginTime}">
				<view class="text-cut">
					主讲人：{{lecture.Hoster}}
				</view>
				<view class="text-cut">
					地点：{{lecture.Address}}
				</view>
				<view class="text-cut" v-if="showBeginTime">
					举办时间：{{dateFormat('YYYY年mm月dd日', lecture.BeginOn)}}
				</view>
			</view>
		</view>
		<view class="action">
			<view v-if="lecture.State === '成功'" class="cu-tag bg-green">{{lecture.State}}</view>
			<view v-else class="cu-tag">{{lecture.State}}</view>
		</view>
	</view>
</template>

<script>
	let app = require("@/config");
	export default {
		props: {
			lecture: {
				type: Object,
				required: true
			},
			showBeginTime: {
				type: Boolean,
				default: false
			}
		},
		data() {
			let avatar = app.webInfo.avatar;
			return {
				avatar
			}
		},
		methods: {
			toDetail(id) {
				uni.navigateTo({
					url: `./detail?id=${this.lecture.ActivityCategoryId}`
				});
			},
			dateFormat(fmt, date) {
				if(date instanceof Date){
					
				}else{
					date = new Date(date.replace(/\-/g, '/'));
				}
				
			    let ret;
			    const opt = {
			        "Y+": date.getFullYear().toString(),        // 年
			        "m+": (date.getMonth() + 1).toString(),     // 月
			        "d+": date.getDate().toString(),            // 日
			        "H+": date.getHours().toString(),           // 时
			        "M+": date.getMinutes().toString(),         // 分
			        "S+": date.getSeconds().toString()          // 秒
			        // 有其他格式化字符需求可以继续添加，必须转化成字符串
			    };
			    for (let k in opt) {
			        ret = new RegExp("(" + k + ")").exec(fmt);
			        if (ret) {
			            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
			        };
			    };
			    return fmt;
			}
		}
	}
</script>

<style>
	.narrow-line{
		line-height: 14px
	}
</style>
